package models

import "time"

// 订单的基础信息
/**

 // online
 已付款和未付款
// 资料
已付款，未付款，待发货，待收货，完成

//offline
提交->待跟进-》招生跟进-》财务复审-》完成。
	Status int `gorm:"type:tinyint(2);not null;default:0;comment:订单状态,默认0,1-待付款，2-已付款，3-完成，4-取消" json:"status"`

**/

// 订单的基础信息

type BaseOrder struct {
	Model
	ModelTime
	OrderNumber string  `gorm:"type:varchar(64);not null;default:'';index;comment:订单编号" json:"order_number"`
	BuyerId     int     `gorm:"type:int(10);not null;default:0;index;comment:买家id" json:"buyer_id"`
	Subject     string  `gorm:"-" json:"subject"`
	SubjectId   int     `gorm:"type:int(10);column:"subject_id",not null;default:0;comment:科目id" json:"subjectId"`
	Province    string  `gorm:"type:varchar(8);not null;default:'';comment:适用大区" json:"province"`
	Price       float64 `gorm:"type:decimal(10,2);comment:价格" json:"price"`
	Commission  float64 `gorm:"type:decimal(10,2);comment:佣金" json:"commission"`
	PayMethod   int     `gorm:"type:tinyint(1);comment:支付方式" json:"pay_method"`
	//InviterId   int     `gorm:"type:int(10);not null;default 0;comment:邀请人id" json:"inviter_id"`
	Postage  float64 `gorm:"type:decimal(10,2);not null;default 0;comment:邮费" json:"postage"`
	TheScore float64 `gorm:"type:decimal(10,2);comment:本次订单获得积分" json:"the_score"`
	PayAt    string  `json:"pay_at" gorm:"comment:支付时间"`
}

type LinkOrder struct {
	Model
	ModelTime
	//商品类型OnlineOrder，MaterialOrder,LiveOrder
	OrderType   string `gorm:"type:varchar(64);default:'';comment:关联的订单类型" json:"order_type"`
	OrderId     int    `gorm:"type:int(10);default:0;index;comment:关联的订单id" json:"order_id"`
	Status      int    `gorm:"type:tinyint(2);not null;default:1;comment:订单状态1->未付款，2-已付款，3-招待发货，4-待收货，5-完成" json:"status"`
	BuyerId     int    `gorm:"type:int(10);not null;default:0;index;comment:买家id" json:"buyer_id"`
	OrderNumber string `gorm:"type:varchar(64);not null;default:'';index;comment:订单编号" json:"order_number"`
}

func (mo LinkOrder) TableName() string {
	return "sys_link_order"
}

// 在线订单
type OnlineOrder struct {
	BaseOrder
	CourseId      int    `gorm:"type:int(10);not null;default:0;comment:课程id" json:"course_id"`
	TeacherId     int    `gorm:"type:int(10);not null;default 0;comment:教师id" json:"teacher_id"`
	Status        int    `gorm:"type:tinyint(2);not null;default:1;comment:订单状态 1-未付款，5-已经付款" json:"status"`
	ShareId       int    `gorm:"type:int(10);not null;default 0;comment:分享者学生id" json:"share_id"`
	IsBindOffline int    `json:"is_bind_offline" gorm:"tinyint(1);default:0;comment:是否关联面授课程"`
	CourseType    string `json:"course_type" gorm:"type:varchar(50);comment:课程类型，online，live"` //课程类型
}

func (on OnlineOrder) TableName() string {
	return "sys_online_order"
}

// 线下订单
type OfflineOrder struct {
	BaseOrder
	CourseId     int `gorm:"type:int(10);not null;default:0;comment:课程id" json:"course_id"`
	DepartmentId int `gorm:"type:int(10);not null;default 0;comment:最基层部门id" json:"department_id"`
	//提交->待跟进-》招生跟进-》财务复审-》完成。
	Status              int    `gorm:"type:tinyint(2);not null;default:1;comment:订单状态1->提交，2-待跟进，3-财务复审，4-完成 " json:"status"`
	FollowUp            string `gorm:"type:varchar(255);default:'';comment:跟进意见" json:"follow_up"`
	ContractNo          string `gorm:"type:varchar(50);default:'';comment:合同编号" json:"contract_no"`
	Recheck             string `gorm:"type:varchar(255);default:'';comment:复审意见" json:"recheck"`
	Communication       string `gorm:"type:varchar(512);default:'',comment:沟通记录" json:"communication"`
	CompletePay         int    `gorm:"type:tinyint(1);default:0;comment:是否完成付款，0-未完成，1-已完成"`
	Name                string `gorm:"type:varchar(50);default:'';comment:买家姓名" json:"name"`
	Phone               string `gorm:"type:varchar(20);default:'';comment:买家电话" json:"phone"`
	TeachingPointId     int    `gorm:"type:int(10);default:0;comment:教学点" json:"teaching_point_id"`
	EnrollmentTeacherId int    `gorm:"type:int(10);default:0;comment:招生老师" json:"enrollment_teacher_id"`
	ReceiptNumber       string `gorm:"type:varchar(255);column:receipt_number" json:"receipt_number"`     //收据编号
	AgreementNumber     string `gorm:"type:varchar(255);column:agreement_number" json:"agreement_number"` //收据编号
	ActualIncome        string `gorm:"type:decimal(10,2);column:actual_income" json:"actual_income"`      //实际收款
	CollegeId           int    `gorm:"type:int(10);default:0;comment:"院校id" json:"college_id"`
	Grade               string `gorm:"type:varchar(200);default:'';comment:年级" json:"grade"`
	KeBie               string `gorm:"type:varchar(200);default:'';comment:科别" json:"ke_bie"`
	Year                int    `gorm:"index;type:int;default:0;comment:订单年份" json:"year"`
	Month               int    `gorm:"index;type:int;default:0;comment:订单月份" json:"month"`
	RecheckUserId       int    `json:"recheck_user_id" gorm:"comment:复审人用户id"`
	ContractUrl         string `json:"contract_url" comment:"合同编号url"`
	ContractNumber      string `json:"contract_number" gorm:"comment:电子合同编号"`
}

func (on OfflineOrder) TableName() string {
	return "sys_offline_order"
}

// 资料订单

type MaterialOrder struct {
	BaseOrder
	//已付款，未付款，待发货，待收货，完成
	Status         int    `gorm:"type:tinyint(2);not null;default:1;comment:订单状态1->未付款，2-已付款，3-招待发货，4-待收货，5-完成" json:"status"`
	Comments       string `gorm:"type:varchar(255);not null;default:'';comment:备注"`
	ExpressNumber  string `gorm:"type:varchar(255);not null;default:'';comment:快递单号"`
	ExpressCompany string `gorm:"type:varchar(255);not null;default:'';comment:快递公司"`
	MaterialId     int    `gorm:"type:int(10);not null;default:0;comment:资料id"`
	//PayAt          time.Time `json:"pay_at" gorm:"comment:付款日期"`
	DeliverId int       `gorm:"type:int(10);not null;default 0;comment:发货人id"`
	Address   string    `gorm:"type:varchar(255);not null;default:'';comment:收获地址"`
	SendAt    time.Time `json:"send_at" gorm:"comment:发货时间"`
}

func (mo MaterialOrder) TableName() string {
	return "sys_material_order"
}

type OnlineOrderCourse struct {
	OrderId  int `json:"order_id" gorm:"index;not null;type:int;comment:订单id"`
	CourseId int `json:"course_id" gorm:"index;not null;type:int;comment:课程id"`
}

func (o OnlineOrderCourse) TableName() string {
	return "online_order_course"
}

type OfflineOrderCourse struct {
	OrderId  int `json:"order_id" gorm:"index;not null;type:int;comment:订单id"`
	CourseId int `json:"course_id" gorm:"index;not null;type:int;comment:课程id"`
}

func (o OfflineOrderCourse) TableName() string {
	return "offline_order_course"
}

type MaterialOrderMaterial struct {
	OrderId    int `json:"order_id" gorm:"index;not null;type:int;comment:订单id"`
	MaterialId int `json:"material_id" gorm:"index;not null;type:int;comment:资料id"`
}

func (o MaterialOrderMaterial) TableName() string {
	return "material_order_material"
}

// 线下订单进度表
type OfflineOrderProgress struct {
	Model
	Creator     string    `json:"creator" gorm:"type:varchar(32);not null;default:'';comment:操作者"`
	Status      int       `json:"status" gorm:"type:tinyint(2);not null;comment:操作时候的订单状态"`
	OrderId     int       `json:"order_id" gorm:"index;type:int;not null;default 0;comment:订单id"`
	OperateTime time.Time `json:"operate_time" gorm:"comment:操作时间"`
	FollowUp    string    `json:"follow_up" gorm:"column:follow_up;type:varchar(512);comment:跟进记录"`
	Remarks     string    `json:"remarks" gorm:"column:remarks;type:varchar(512);comment:备注"`
}

func (o OfflineOrderProgress) TableName() string {
	return "offline_order_progress"
}
